package com.td.module.farmer.dal.mysql.consultation;

import com.td.framework.common.pojo.PageResult;
import com.td.framework.mybatis.core.mapper.BaseMapperX;
import com.td.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.td.module.farmer.controller.admin.consultation.vo.ConsultationExportReqVO;
import com.td.module.farmer.controller.admin.consultation.vo.ConsultationPageReqVO;
import com.td.module.farmer.dal.dataobject.consultation.ConsultationDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 农事咨询 Mapper
 *
 * @author 王翔翔
 */
@Mapper
public interface ConsultationMapper extends BaseMapperX<ConsultationDO> {

    default PageResult<ConsultationDO> selectPage(ConsultationPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ConsultationDO>()
                .likeIfPresent(ConsultationDO::getAgriculturalIssues, reqVO.getAgriculturalIssues())
                .eqIfPresent(ConsultationDO::getConsultant, reqVO.getConsultant())
                .eqIfPresent(ConsultationDO::getUserId, reqVO.getUserId())
                .eqIfPresent(ConsultationDO::getWhetherView, reqVO.getWhetherView())
                .eqIfPresent(ConsultationDO::getQuestionAnswering, reqVO.getQuestionAnswering())
                .eqIfPresent(ConsultationDO::getRespondent, reqVO.getRespondent())
                .betweenIfPresent(ConsultationDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ConsultationDO::getId));
    }

    default List<ConsultationDO> selectList(ConsultationExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<ConsultationDO>()
                .likeIfPresent(ConsultationDO::getAgriculturalIssues, reqVO.getAgriculturalIssues())
                .eqIfPresent(ConsultationDO::getConsultant, reqVO.getConsultant())
                .eqIfPresent(ConsultationDO::getUserId, reqVO.getUserId())
                .eqIfPresent(ConsultationDO::getQuestionAnswering, reqVO.getQuestionAnswering())
                .eqIfPresent(ConsultationDO::getRespondent, reqVO.getRespondent())
                .eqIfPresent(ConsultationDO::getWhetherView, reqVO.getWhetherView())
                .betweenIfPresent(ConsultationDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ConsultationDO::getId));
    }

}
